module.exports = {
    Query: {
      async accountList (root, args, ctx) {
        const { app } = ctx;
        const result = await app.mysql.query('select * from account');
        console.log(result, '查询数据');
        return result;
      }
    },
    Mutation: {
      async createAccount(root, args, ctx) {
        const { app } = ctx;
        console.log(args, '获取的参数');
        const username = args.username;
        const password = args.password;
        const result = await app.mysql.query('insert into account(username, password) values(?,?)', [username, password]);
        if (result && result.affectedRows) {
          return '插入成功';
        } else {
          return '插入失败';
        }
      },
      async modifyAccountById(root, args, ctx){
        const { app } = ctx;
        console.log(args, '获取的参数');
        const id = args.id;
        const {username,password } = args.data;
        const result = await app.mysql.query('update account set username = ?, password = ? where id = ?', [username,password, id]);
        if (result && result.affectedRows) {
          return '插入成功';
        } else {
          return '插入失败';
        }
      }
    }
  }